<template>
  <van-icon
    slot="right-icon"
    :color="cmt.is_liking ? 'red' : '#777'"
    :name="cmt.is_liking ? 'like' : 'like-o'"
    @click="doLike"
  />
</template>

<script>
import { likeCMT, dislikeCMT } from '@/api/comment.js'

export default {
  name: '',
  props: {
    // 评论对象
    cmt: {
      type: Object,
      required: true
    }
  },
  data() {
    return {}
  },
  created() {},
  methods: {
    // 1.点赞/取消赞--------------------------
    async doLike() {
      try {
        if (this.cmt.is_liking) {
          // 取消评论 点赞
          await dislikeCMT(this.cmt.com_id)
        } else {
          // 对评论 点赞
          await likeCMT(this.cmt.com_id)
        }
        this.$toast.success('操作成功~')
        // 修改数据：喜欢状态 取反
        this.cmt.is_liking = !this.cmt.is_liking
      } catch (err) {
        this.$toast.fail('服务器繁忙，请明年再试~')
      }
    }
  },
  computed: {},
  watch: {},
  components: {}
}
</script>

<style lang="less" scoped>
</style>
